package com.qyy.www_chatroom.controller;

import com.qyy.www_chatroom.mapper.MessageMapper;
import com.qyy.www_chatroom.model.Message;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Collection;
import java.util.Collections;
import java.util.List;

@RestController
public class MessageController {

    @Autowired
    private MessageMapper messageMapper;

    @RequestMapping("/message")
    public Object getMessage(int sessionId){
        List<Message> messages = messageMapper.getMessageBySessionId(sessionId);
        System.out.println("+++++++++++++++++++++++++++++++++++++++++++++++"+messages);
        /**
         * 数据库查出来的消息是按时间降序。因此最新的消息在最前面。因此还需要逆序一下
         */
        //集合
        Collections.reverse(messages);
        System.out.println("+++++++++++++++++++++++++++++++++++++++++++++++"+messages);
        return messages;
    }
}
